
import { Form, Input, InputNumber } from 'antd';
import React from 'react';

export const renderItem = (it: any, detail: any) => {
  const { name, required = false, key } = it;
  let element: any = null;
  switch (it.type) {
    case 'input':
      element = <Input placeholder={`请输入${name}`} />
      break;
    case 'inputNumber':
      element = <InputNumber placeholder={`请输入${name}`} />
      break;
    case 'textarea':
      element = <Input.TextArea placeholder={`请输入${name}`} />
      break;
    default:
      element = it.render(it, detail);
      break;
  };
  return (
    <Form.Item
      label={name}
      name={key}
      rules={[{
        required,
        message: `请输入${name}`
      }]}
    >
      {element}
    </Form.Item>
  )
}
